package dataBase;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SpinnerDateModel;
import javax.swing.plaf.basic.BasicBorders.SplitPaneBorder;
import project.Project;
import java.applet.Applet;
import java.awt.*;
import java.io.FileInputStream;

 public class ProjectBD extends Conexao 
{
	private static String Query = new String();
	private static ResultSet rs = null;
	private static  ProjectBD p = new ProjectBD();
	public ProjectBD() {
		super();
	}
	public static ProjectBD getInstance(){
		return p;
	}
	
	public boolean insert(Project project){

		String Query = "INSERT INTO project (name,idUser,stepCode,date) " +
		" VALUES ('" +
		project.nome +"','"+
		project.designer.id +"','"+
		project.stepCode +"'," +
		"CURRENT_DATE)";		
		System.out.println(Query);
		try	{
			Statement statement = conn.createStatement();
			statement.executeUpdate(Query);
			return true;
		}
		catch (SQLException e){
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, "Error, try again later.", "Error", 0);
		}		
		return false;
	}
	public Project get(int id){
		String Query ="select stepCode from project where id ="+id;
		try	{
			Statement statement = conn.createStatement();
			rs=statement.executeQuery(Query);
			
			return new Project(rs.getString("stepCode"));
		}
		catch (SQLException e){
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, "Error, try again later.", "Error", 0);
		}		
		return null;
	}
	
}